home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / calendar / holidays.el < prev    next >
Encoding:
Text File  |  1995-03-25  |  27.3 KB  |  630 lines

  1. ;;; holidays.el --- holiday functions for the calendar package
  2.  
  3. ;;; Copyright (C) 1989, 1990, 1992, 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
  6. ;; Keywords: holidays, calendar
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; This collection of functions implements the holiday features as described
  27. ;; in calendar.el.
  28.  
  29. ;; Comments, corrections, and improvements should be sent to
  30. ;;  Edward M. Reingold               Department of Computer Science
  31. ;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
  32. ;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
  33. ;;                                   Urbana, Illinois 61801
  34.  
  35. ;; Technical details of all the calendrical calculations can be found in
  36. ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
  37. ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
  38. ;; pages 899-928.  ``Calendrical Calculations, Part II: Three Historical
  39. ;; Calendars'' by E. M. Reingold,  N. Dershowitz, and S. M. Clamen,
  40. ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
  41. ;; pages 383-404.
  42.  
  43. ;; Hard copies of these two papers can be obtained by sending email to
  44. ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
  45. ;; the message BODY containing your mailing address (snail).
  46.  
  47. ;;; Code:
  48.  
  49. (require 'calendar)
  50.  
  51. (autoload 'solar-equinoxes-solstices "solar"
  52.   "Date and time of equinoxes and solstices, if visible in the calendar window.
  53. Requires floating point."
  54.   t)
  55.  
  56. ;;;###autoload
  57. (defun holidays (&optional arg)
  58.   "Display the holidays for last month, this month, and next month.
  59. If called with an optional prefix argument, prompts for month and year.
  60.  
  61. This function is suitable for execution in a .emacs file."
  62.   (interactive "P")
  63.   (save-excursion
  64.     (let* ((completion-ignore-case t)
  65.            (date (if arg
  66.                      (calendar-read-date t)
  67.                    (calendar-current-date)))
  68.            (displayed-month (extract-calendar-month date))
  69.            (displayed-year (extract-calendar-year date)))
  70.       (list-calendar-holidays))))
  71.  
  72. (defun check-calendar-holidays (date)
  73.   "Check the list of holidays for any that occur on DATE.
  74. The value returned is a list of strings of relevant holiday descriptions.
  75. The holidays are those in the list calendar-holidays."
  76.   (let* ((displayed-month (extract-calendar-month date))
  77.          (displayed-year (extract-calendar-year date))
  78.          (h (calendar-holiday-list))
  79.          (holiday-list))
  80.     (while h
  81.       (if (calendar-date-equal date (car (car h)))
  82.           (setq holiday-list (append holiday-list (cdr (car h)))))
  83.       (setq h (cdr h)))
  84.     holiday-list))
  85.  
  86. (defun calendar-cursor-holidays ()
  87.   "Find holidays for the date specified by the cursor in the calendar window."
  88.   (interactive)
  89.   (message "Checking holidays...")
  90.   (let* ((date (calendar-cursor-to-date t))
  91.          (date-string (calendar-date-string date))
  92.          (holiday-list (check-calendar-holidays date))
  93.          (holiday-string (mapconcat 'identity holiday-list ";  "))
  94.          (msg (format "%s:  %s" date-string holiday-string)))
  95.     (if (not holiday-list)
  96.         (message "No holidays known for %s" date-string)
  97.       (if (<= (length msg) (frame-width))
  98.           (message msg)
  99.         (set-buffer (get-buffer-create holiday-buffer))
  100.         (setq buffer-read-only nil)
  101.         (calendar-set-mode-line date-string)
  102.         (erase-buffer)
  103.         (insert (mapconcat 'identity holiday-list "\n"))
  104.         (goto-char (point-min))
  105.         (set-buffer-modified-p nil)
  106.         (setq buffer-read-only t)
  107.         (display-buffer holiday-buffer)
  108.         (message "Checking holidays...done")))))
  109.  
  110. (defun mark-calendar-holidays ()
  111.   "Mark notable days in the calendar window."
  112.   (interactive)
  113.   (setq mark-holidays-in-calendar t)
  114.   (message "Marking holidays...")
  115.   (let ((holiday-list (calendar-holiday-list)))
  116.     (while holiday-list
  117.       (mark-visible-calendar-date
  118.        (car (car holiday-list)) calendar-holiday-marker)
  119.       (setq holiday-list (cdr holiday-list))))
  120.   (message "Marking holidays...done"))
  121.  
  122. (defun list-calendar-holidays ()
  123.   "Create a buffer containing the holidays for the current calendar window.
  124. The holidays are those in the list calendar-notable-days.  Returns t if any
  125. holidays are found, nil if not."
  126.   (interactive)
  127.   (message "Looking up holidays...")
  128.   (let ((holiday-list (calendar-holiday-list))
  129.         (m1 displayed-month)
  130.         (y1 displayed-year)
  131.         (m2 displayed-month)
  132.         (y2 displayed-year))
  133.     (if (not holiday-list)
  134.         (progn
  135.           (message "Looking up holidays...none found")
  136.           nil)
  137.       (set-buffer (get-buffer-create holiday-buffer))
  138.       (setq buffer-read-only nil)
  139.       (increment-calendar-month m1 y1 -1)
  140.       (increment-calendar-month m2 y2 1)
  141.       (calendar-set-mode-line
  142.        (if (= y1 y2)
  143.            (format "Notable Dates from %s to %s, %d%%-"
  144.                    (calendar-month-name m1) (calendar-month-name m2) y2)
  145.          (format "Notable Dates from %s, %d to %s, %d%%-"
  146.                  (calendar-month-name m1) y1 (calendar-month-name m2) y2)))
  147.       (erase-buffer)
  148.       (insert
  149.        (mapconcat
  150.         '(lambda (x) (concat (calendar-date-string (car x))
  151.                              ": " (car (cdr x))))
  152.         holiday-list "\n"))
  153.       (goto-char (point-min))
  154.       (set-buffer-modified-p nil)
  155.       (setq buffer-read-only t)
  156.       (display-buffer holiday-buffer)
  157.       (message "Looking up holidays...done")
  158.       t)))
  159.  
  160. (defun calendar-holiday-list ()
  161.   "Form the list of holidays that occur on dates in the calendar window.
  162. The holidays are those in the list calendar-holidays."
  163.   (let ((p calendar-holidays)
  164.         (holiday-list))
  165.     (while p
  166.       (let* ((holidays
  167.               (if calendar-debug-sexp
  168.                   (let ((stack-trace-on-error t))
  169.                     (eval (car p)))
  170.                 (condition-case nil
  171.                     (eval (car p))
  172.                   (error (beep)
  173.                          (message "Bad holiday list item: %s" (car p))
  174.                          (sleep-for 2))))))
  175.         (if holidays
  176.             (setq holiday-list (append holidays holiday-list))))
  177.       (setq p (cdr p)))
  178.     (setq holiday-list (sort holiday-list 'calendar-date-compare))))
  179.  
  180. ;; Below are the functions that calculate the dates of holidays; these
  181. ;; are eval'ed in the function calendar-holiday-list.  If you
  182. ;; write other such functions, be sure to imitate the style used below.
  183. ;; Remember that each function must return a list of items of the form
  184. ;; ((month day year) string) of VISIBLE dates in the calendar window.
  185.  
  186. (defun holiday-fixed (month day string)
  187.   "Holiday on MONTH, DAY (Gregorian) called STRING.
  188. If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
  189. STRING)).  Returns nil if it is not visible in the current calendar window."
  190.   (let ((m displayed-month)
  191.         (y displayed-year))
  192.     (increment-calendar-month m y (- 11 month))
  193.     (if (> m 9)
  194.       (list (list (list month day y) string)))))
  195.  
  196. (defun holiday-float (month dayname n string &optional day)
  197.   "Holiday on MONTH, DAYNAME (Nth occurrence, Gregorian) called STRING.
  198. If the Nth DAYNAME in MONTH is visible, the value returned is the list
  199. \(((MONTH DAY year) STRING)).
  200.  
  201. If N<0, count backward from the end of MONTH.
  202.  
  203. An optional parameter DAY means the Nth DAYNAME after/before MONTH DAY.
  204.  
  205. Returns nil if it is not visible in the current calendar window."
  206.   (let ((m displayed-month)
  207.         (y displayed-year))
  208.     (increment-calendar-month m y (- 11 month))
  209.     (if (> m 9)
  210.       (list (list (calendar-nth-named-day n dayname month y day) string)))))
  211.  
  212. (defun holiday-julian (month day string)
  213.   "Holiday on MONTH, DAY  (Julian) called STRING.
  214. If MONTH, DAY (Julian) is visible, the value returned is corresponding
  215. Gregorian date in the form of the list (((month day year) STRING)).  Returns
  216. nil if it is not visible in the current calendar window."
  217.   (let ((m1 displayed-month)
  218.         (y1 displayed-year)
  219.         (m2 displayed-month)
  220.         (y2 displayed-year)
  221.         (year))
  222.     (increment-calendar-month m1 y1 -1)
  223.     (increment-calendar-month m2 y2 1)
  224.     (let* ((start-date (calendar-absolute-from-gregorian
  225.                         (list m1 1 y1)))
  226.            (end-date (calendar-absolute-from-gregorian
  227.                       (list m2 (calendar-last-day-of-month m2 y2) y2)))
  228.            (julian-start (calendar-julian-from-absolute start-date))
  229.            (julian-end (calendar-julian-from-absolute end-date))
  230.            (julian-y1 (extract-calendar-year julian-start))
  231.            (julian-y2 (extract-calendar-year julian-end)))
  232.       (setq year (if (< 10 month) julian-y1 julian-y2))
  233.       (let ((date (calendar-gregorian-from-absolute
  234.                    (calendar-absolute-from-julian
  235.                     (list month day year)))))
  236.         (if (calendar-date-is-visible-p date)
  237.             (list (list date string)))))))
  238.  
  239. (defun holiday-islamic (month day string)
  240.   "Holiday on MONTH, DAY (Islamic) called STRING.
  241. If MONTH, DAY (Islamic) is visible, the value returned is corresponding
  242. Gregorian date in the form of the list (((month day year) STRING)).  Returns
  243. nil if it is not visible in the current calendar window."
  244.   (let* ((islamic-date (calendar-islamic-from-absolute
  245.                         (calendar-absolute-from-gregorian
  246.                          (list displayed-month 15 displayed-year))))
  247.          (m (extract-calendar-month islamic-date))
  248.          (y (extract-calendar-year islamic-date))
  249.         (date))
  250.     (if (< m 1)
  251.         nil;;   Islamic calendar doesn't apply.
  252.       (increment-calendar-month m y (- 10 month))
  253.       (if (> m 7);;  Islamic date might be visible
  254.           (let ((date (calendar-gregorian-from-absolute
  255.                        (calendar-absolute-from-islamic (list month day y)))))
  256.             (if (calendar-date-is-visible-p date)
  257.                 (list (list date string))))))))
  258.  
  259. (defun holiday-hebrew (month day string)
  260.   "Holiday on MONTH, DAY (Hebrew) called STRING.
  261. If MONTH, DAY (Hebrew) is visible, the value returned is corresponding
  262. Gregorian date in the form of the list (((month day year) STRING)).  Returns
  263. nil if it is not visible in the current calendar window."
  264.   (if (memq displayed-month;;  This test is only to speed things up a bit;
  265.             (list          ;;  it works fine without the test too.
  266.              (if (< 11 month) (- month 11) (+ month 1))
  267.              (if (< 10 month) (- month 10) (+ month 2))
  268.              (if (<  9 month) (- month  9) (+ month 3))
  269.              (if (<  8 month) (- month  8) (+ month 4))
  270.              (if (<  7 month) (- month  7) (+ month 5))))
  271.       (let ((m1 displayed-month)
  272.             (y1 displayed-year)
  273.             (m2 displayed-month)
  274.             (y2 displayed-year)
  275.             (year))
  276.         (increment-calendar-month m1 y1 -1)
  277.         (increment-calendar-month m2 y2 1)
  278.         (let* ((start-date (calendar-absolute-from-gregorian
  279.                             (list m1 1 y1)))
  280.                (end-date (calendar-absolute-from-gregorian
  281.                           (list m2 (calendar-last-day-of-month m2 y2) y2)))
  282.                (hebrew-start (calendar-hebrew-from-absolute start-date))
  283.                (hebrew-end (calendar-hebrew-from-absolute end-date))
  284.                (hebrew-y1 (extract-calendar-year hebrew-start))
  285.                (hebrew-y2 (extract-calendar-year hebrew-end)))
  286.           (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
  287.           (let ((date (calendar-gregorian-from-absolute
  288.                        (calendar-absolute-from-hebrew
  289.                         (list month day year)))))
  290.             (if (calendar-date-is-visible-p date)
  291.                 (list (list date string))))))))
  292.  
  293. (defun holiday-sexp (sexp string)
  294.   "Sexp holiday for dates in the calendar window.
  295. SEXP is an expression in variable `year' evaluates to `date'.
  296.  
  297. STRING is an expression in `date' that evaluates to the holiday description
  298. of `date'.
  299.  
  300. If `date' is visible in the calendar window, the holiday STRING is on that
  301. date.  If date is nil, or if the date is not visible, there is no holiday."
  302.   (let ((m displayed-month)
  303.         (y displayed-year))
  304.     (increment-calendar-month m y -1)
  305.     (filter-visible-calendar-holidays
  306.      (append
  307.       (let* ((year y)
  308.              (date (eval sexp))
  309.              (string (if date (eval string))))
  310.         (list (list date string)))
  311.       (let* ((year (1+ y))
  312.              (date (eval sexp))
  313.              (string (if date (eval string))))
  314.         (list (list date string)))))))
  315.  
  316. (defun holiday-advent ()
  317.   "Date of Advent, if visible in calendar window."
  318.   (let ((year displayed-year)
  319.         (month displayed-month))
  320.     (increment-calendar-month month year -1)
  321.     (let ((advent (calendar-gregorian-from-absolute
  322.                    (calendar-dayname-on-or-before 0
  323.                     (calendar-absolute-from-gregorian
  324.                      (list 12 3 year))))))
  325.       (if (calendar-date-is-visible-p advent)
  326.           (list (list advent "Advent"))))))
  327.  
  328. (defun holiday-easter-etc ()
  329.   "List of dates related to Easter, as visible in calendar window."
  330.  (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
  331.      nil;; Ash Wednesday, Good Friday, and Easter are not visible.
  332.    (let* ((century (1+ (/ displayed-year 100)))
  333.           (shifted-epact        ;; Age of moon for April 5...
  334.            (% (+ 14 (* 11 (% displayed-year 19));;     ...by Nicaean rule
  335.                  (-           ;; ...corrected for the Gregorian century rule
  336.                   (/ (* 3 century) 4))
  337.                  (/    ;; ...corrected for Metonic cycle inaccuracy.
  338.                   (+ 5 (* 8 century)) 25)
  339.                  (* 30 century));;              Keeps value positive.
  340.               30))
  341.           (adjusted-epact       ;;  Adjust for 29.5 day month.
  342.            (if (or (= shifted-epact 0)
  343.                    (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
  344.                (1+ shifted-epact)
  345.              shifted-epact))
  346.           (paschal-moon       ;; Day after the full moon on or after March 21.
  347.            (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
  348.               adjusted-epact))
  349.           (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
  350.           (mandatory
  351.            (list
  352.             (list (calendar-gregorian-from-absolute abs-easter)
  353.                   "Easter Sunday")
  354.             (list (calendar-gregorian-from-absolute (- abs-easter 2))
  355.                   "Good Friday")
  356.             (list (calendar-gregorian-from-absolute (- abs-easter 46))
  357.                   "Ash Wednesday")))
  358.           (optional
  359.            (list
  360.             (list (calendar-gregorian-from-absolute (- abs-easter 63))
  361.                   "Septuagesima Sunday")
  362.             (list (calendar-gregorian-from-absolute (- abs-easter 56))
  363.                   "Sexagesima Sunday")
  364.             (list (calendar-gregorian-from-absolute (- abs-easter 49))
  365.                   "Shrove Sunday")
  366.             (list (calendar-gregorian-from-absolute (- abs-easter 48))
  367.                   "Shrove Monday")
  368.             (list (calendar-gregorian-from-absolute (- abs-easter 47))
  369.                   "Shrove Tuesday")
  370.             (list (calendar-gregorian-from-absolute (- abs-easter 14))
  371.                   "Passion Sunday")
  372.             (list (calendar-gregorian-from-absolute (- abs-easter 7))
  373.                   "Palm Sunday")
  374.             (list (calendar-gregorian-from-absolute (- abs-easter 3))
  375.                   "Maundy Thursday")
  376.             (list (calendar-gregorian-from-absolute (+ abs-easter 35))
  377.                   "Rogation Sunday")
  378.             (list (calendar-gregorian-from-absolute (+ abs-easter 39))
  379.                   "Ascension Day")
  380.             (list (calendar-gregorian-from-absolute (+ abs-easter 49))
  381.                   "Pentecost (Whitsunday)")
  382.             (list (calendar-gregorian-from-absolute (+ abs-easter 50))
  383.                   "Whitmunday")
  384.             (list (calendar-gregorian-from-absolute (+ abs-easter 56))
  385.                   "Trinity Sunday")
  386.             (list (calendar-gregorian-from-absolute (+ abs-easter 60))
  387.                   "Corpus Christi")))
  388.           (output-list
  389.            (filter-visible-calendar-holidays mandatory)))
  390.      (if all-christian-calendar-holidays
  391.          (setq output-list
  392.                (append 
  393.                 (filter-visible-calendar-holidays optional)
  394.                 output-list)))
  395.      output-list)))
  396.  
  397. (defun holiday-greek-orthodox-easter ()
  398.   "Date of Easter according to the rule of the Council of Nicaea."
  399.   (let ((m displayed-month)
  400.         (y displayed-year))
  401.     (increment-calendar-month m y 1)
  402.     (let* ((julian-year
  403.             (extract-calendar-year
  404.              (calendar-julian-from-absolute
  405.               (calendar-absolute-from-gregorian
  406.                (list m (calendar-last-day-of-month m y) y)))))
  407.            (shifted-epact ;; Age of moon for April 5.
  408.             (% (+ 14
  409.                   (* 11 (% julian-year 19)))
  410.                30))
  411.            (paschal-moon  ;; Day after full moon on or after March 21.
  412.             (- (calendar-absolute-from-julian (list 4 19 julian-year))
  413.                shifted-epact))
  414.            (nicaean-easter;; Sunday following the Paschal moon
  415.             (calendar-gregorian-from-absolute
  416.              (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))))
  417.       (if (calendar-date-is-visible-p nicaean-easter)
  418.           (list (list nicaean-easter "Pascha (Greek Orthodox Easter)"))))))
  419.  
  420. (defun holiday-rosh-hashanah-etc ()
  421.   "List of dates related to Rosh Hashanah, as visible in calendar window."
  422.   (if (or (< displayed-month 8)
  423.           (> displayed-month 11))
  424.       nil;; None of the dates is visible
  425.     (let* ((abs-r-h (calendar-absolute-from-hebrew
  426.                       (list 7 1 (+ displayed-year 3761))))
  427.             (mandatory
  428.              (list
  429.               (list (calendar-gregorian-from-absolute abs-r-h)
  430.                     (format "Rosh HaShanah %d" (+ 3761 displayed-year)))
  431.               (list (calendar-gregorian-from-absolute (+ abs-r-h 9))
  432.                     "Yom Kippur")
  433.               (list (calendar-gregorian-from-absolute (+ abs-r-h 14))
  434.                     "Sukkot")
  435.               (list (calendar-gregorian-from-absolute (+ abs-r-h 21))
  436.                     "Shemini Atzeret")
  437.               (list (calendar-gregorian-from-absolute (+ abs-r-h 22))
  438.                     "Simchat Torah")))
  439.            (optional
  440.             (list 
  441.              (list (calendar-gregorian-from-absolute
  442.                     (calendar-dayname-on-or-before 6 (- abs-r-h 4)))
  443.                    "Selichot (night)")
  444.              (list (calendar-gregorian-from-absolute (1- abs-r-h))
  445.                    "Erev Rosh HaShannah")
  446.              (list (calendar-gregorian-from-absolute (1+ abs-r-h))
  447.                    "Rosh HaShanah (second day)")
  448.              (list (calendar-gregorian-from-absolute
  449.                     (if (= (% abs-r-h 7) 4) (+ abs-r-h 3) (+ abs-r-h 2)))
  450.                    "Tzom Gedaliah")
  451.              (list (calendar-gregorian-from-absolute
  452.                     (calendar-dayname-on-or-before 6 (+ 7 abs-r-h)))
  453.                    "Shabbat Shuvah")
  454.              (list (calendar-gregorian-from-absolute (+ abs-r-h 8))
  455.                    "Erev Yom Kippur")
  456.              (list (calendar-gregorian-from-absolute (+ abs-r-h 13))
  457.                    "Erev Sukkot")
  458.              (list (calendar-gregorian-from-absolute (+ abs-r-h 15))
  459.                    "Sukkot (second day)")
  460.              (list (calendar-gregorian-from-absolute (+ abs-r-h 16))
  461.                    "Hol Hamoed Sukkot (first day)")
  462.              (list (calendar-gregorian-from-absolute (+ abs-r-h 17))
  463.                    "Hol Hamoed Sukkot (second day)")
  464.              (list (calendar-gregorian-from-absolute (+ abs-r-h 18))
  465.                    "Hol Hamoed Sukkot (third day)")
  466.              (list (calendar-gregorian-from-absolute (+ abs-r-h 19))
  467.                    "Hol Hamoed Sukkot (fourth day)")
  468.              (list (calendar-gregorian-from-absolute (+ abs-r-h 20))
  469.                    "Hoshannah Rabbah")))
  470.             (output-list
  471.              (filter-visible-calendar-holidays mandatory)))
  472.       (if all-hebrew-calendar-holidays
  473.           (setq output-list
  474.                 (append 
  475.                  (filter-visible-calendar-holidays optional)
  476.                  output-list)))
  477.       output-list)))
  478.  
  479. (defun holiday-hanukkah ()
  480.   "List of dates related to Hanukkah, as visible in calendar window."
  481.     (if (memq displayed-month;;  This test is only to speed things up a bit;
  482.               '(10 11 12 1 2));; it works fine without the test too.
  483.         (let ((m displayed-month)
  484.               (y displayed-year))
  485.           (increment-calendar-month m y 1)
  486.           (let* ((h-y (extract-calendar-year
  487.                          (calendar-hebrew-from-absolute
  488.                           (calendar-absolute-from-gregorian
  489.                            (list m (calendar-last-day-of-month m y) y)))))
  490.                  (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y))))
  491.             (filter-visible-calendar-holidays
  492.              (list
  493.               (list (calendar-gregorian-from-absolute (1- abs-h))
  494.                     "Erev Hanukkah")
  495.               (list (calendar-gregorian-from-absolute abs-h)
  496.                     "Hanukkah (first day)")
  497.               (list (calendar-gregorian-from-absolute (1+ abs-h))
  498.                     "Hanukkah (second day)")
  499.               (list (calendar-gregorian-from-absolute (+ abs-h 2))
  500.                     "Hanukkah (third day)")
  501.               (list (calendar-gregorian-from-absolute (+ abs-h 3))
  502.                     "Hanukkah (fourth day)")
  503.               (list (calendar-gregorian-from-absolute (+ abs-h 4))
  504.                     "Hanukkah (fifth day)")
  505.               (list (calendar-gregorian-from-absolute (+ abs-h 5))
  506.                     "Hanukkah (sixth day)")
  507.               (list (calendar-gregorian-from-absolute (+ abs-h 6))
  508.                     "Hanukkah (seventh day)")
  509.               (list (calendar-gregorian-from-absolute (+ abs-h 7))
  510.                     "Hanukkah (eighth day)")))))))
  511.  
  512. (defun holiday-passover-etc ()
  513.   "List of dates related to Passover, as visible in calendar window."
  514.  (if (< 7 displayed-month)
  515.       nil;; None of the dates is visible
  516.     (let* ((abs-p (calendar-absolute-from-hebrew
  517.                       (list 1 15 (+ displayed-year 3760))))
  518.            (mandatory
  519.             (list
  520.              (list (calendar-gregorian-from-absolute abs-p)
  521.                    "Passover")
  522.              (list (calendar-gregorian-from-absolute (+ abs-p 50))
  523.                    "Shavuot")))
  524.            (optional
  525.             (list 
  526.              (list (calendar-gregorian-from-absolute
  527.                     (calendar-dayname-on-or-before 6 (- abs-p 43)))
  528.                    "Shabbat Shekalim")
  529.              (list (calendar-gregorian-from-absolute
  530.                     (calendar-dayname-on-or-before 6 (- abs-p 30)))
  531.                    "Shabbat Zachor")
  532.              (list (calendar-gregorian-from-absolute
  533.                     (if (= (% abs-p 7) 2) (- abs-p 33) (- abs-p 31)))
  534.                    "Fast of Esther")
  535.              (list (calendar-gregorian-from-absolute (- abs-p 31))
  536.                    "Erev Purim")
  537.              (list (calendar-gregorian-from-absolute (- abs-p 30))
  538.                    "Purim")
  539.              (list (calendar-gregorian-from-absolute
  540.                     (if (zerop (% abs-p 7)) (- abs-p 28) (- abs-p 29)))
  541.                    "Shushan Purim")
  542.              (list (calendar-gregorian-from-absolute
  543.                     (- (calendar-dayname-on-or-before 6 (- abs-p 14)) 7))
  544.                    "Shabbat Parah")
  545.              (list (calendar-gregorian-from-absolute
  546.                     (calendar-dayname-on-or-before 6 (- abs-p 14)))
  547.                    "Shabbat HaHodesh")
  548.              (list (calendar-gregorian-from-absolute
  549.                     (calendar-dayname-on-or-before 6 (1- abs-p)))
  550.                    "Shabbat HaGadol")
  551.              (list (calendar-gregorian-from-absolute (1- abs-p))
  552.                    "Erev Passover")
  553.              (list (calendar-gregorian-from-absolute (1+ abs-p))
  554.                    "Passover (second day)")
  555.              (list (calendar-gregorian-from-absolute (+ abs-p 2))
  556.                    "Hol Hamoed Passover (first day)")
  557.              (list (calendar-gregorian-from-absolute (+ abs-p 3))
  558.                    "Hol Hamoed Passover (second day)")
  559.              (list (calendar-gregorian-from-absolute (+ abs-p 4))
  560.                    "Hol Hamoed Passover (third day)")
  561.              (list (calendar-gregorian-from-absolute (+ abs-p 5))
  562.                    "Hol Hamoed Passover (fourth day)")
  563.              (list (calendar-gregorian-from-absolute (+ abs-p 6))
  564.                    "Passover (seventh day)")
  565.              (list (calendar-gregorian-from-absolute (+ abs-p 7))
  566.                    "Passover (eighth day)")
  567.              (list (calendar-gregorian-from-absolute (+ abs-p 12))
  568.                    "Yom HaShoah")
  569.              (list (calendar-gregorian-from-absolute
  570.                     (if (zerop (% abs-p 7))
  571.                         (+ abs-p 18)
  572.                       (if (= (% abs-p 7) 6)
  573.                           (+ abs-p 19)
  574.                         (+ abs-p 20))))
  575.                    "Yom HaAtzma'ut")
  576.              (list (calendar-gregorian-from-absolute (+ abs-p 33))
  577.                    "Lag BaOmer")
  578.              (list (calendar-gregorian-from-absolute (+ abs-p 43))
  579.                    "Yom Yerushalim")
  580.              (list (calendar-gregorian-from-absolute (+ abs-p 49))
  581.                    "Erev Shavuot")
  582.              (list (calendar-gregorian-from-absolute (+ abs-p 51))
  583.                    "Shavuot (second day)")))
  584.            (output-list
  585.              (filter-visible-calendar-holidays mandatory)))
  586.       (if all-hebrew-calendar-holidays
  587.           (setq output-list
  588.                 (append 
  589.                  (filter-visible-calendar-holidays optional)
  590.                  output-list)))
  591.       output-list)))
  592.  
  593. (defun holiday-tisha-b-av-etc ()
  594.   "List of dates around Tisha B'Av, as visible in calendar window."
  595.   (if (or (< displayed-month 5)
  596.           (> displayed-month 9))
  597.       nil;; None of the dates is visible
  598.     (let* ((abs-t-a (calendar-absolute-from-hebrew
  599.                       (list 5 9 (+ displayed-year 3760)))))
  600.  
  601.       (filter-visible-calendar-holidays
  602.        (list 
  603.         (list (calendar-gregorian-from-absolute
  604.                (if (= (% abs-t-a 7) 6) (- abs-t-a 20) (- abs-t-a 21)))
  605.               "Tzom Tammuz")
  606.         (list (calendar-gregorian-from-absolute
  607.                (calendar-dayname-on-or-before 6 abs-t-a))
  608.               "Shabbat Hazon")
  609.         (list (calendar-gregorian-from-absolute
  610.                (if (= (% abs-t-a 7) 6) (1+ abs-t-a) abs-t-a))
  611.               "Tisha B'Av")
  612.         (list (calendar-gregorian-from-absolute
  613.                (calendar-dayname-on-or-before 6 (+ abs-t-a 7)))
  614.               "Shabbat Nahamu"))))))
  615.  
  616. (defun filter-visible-calendar-holidays (l)
  617.   "Return a list of all visible holidays of those on L."
  618.   (let ((visible)
  619.         (p l))
  620.     (while p
  621.       (and (car (car p))
  622.            (calendar-date-is-visible-p (car (car p)))
  623.            (setq visible (append (list (car p)) visible)))
  624.       (setq p (cdr p)))
  625.     visible))
  626.  
  627. (provide 'holidays)
  628.  
  629. ;;; holidays.el ends here
  630.